/* Team 5
 * James McQueen
 * Corwyn Simpson
 * May 1 ish, 2012
 */
package spider.ui;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 *
 * @author James McQueen
 */
public class TimerPanel extends JPanel
{
    public static final Color TIME_ELAPSED_COLOR = Color.RED;
    public static final Color TIME_SINGLE_COLOR = Color.ORANGE;
    public static final Color TIME_SUFFIX_COLOR = Color.WHITE;
    public static final Color CUSTOM_COLOR = new Color(55,50,200);
    public static final Dimension SIZE = new Dimension(220, 20);
    private String my_total_elapsed;
    private String my_single_elapsed;
    private String my_total_sec;
    private String my_single_sec;
    
    public TimerPanel()
    {
        super();
        my_total_elapsed = "n/a";
        my_single_elapsed = "n/a";
        my_total_sec = "n/a";
        my_single_sec = "n/a";
        setPreferredSize(SIZE);
        setMaximumSize(SIZE);
        final Font font = new Font("Serif", Font.BOLD, 16);
        setFont(font);
        setBackground(CUSTOM_COLOR.brighter());
        setForeground(Color.WHITE);
  }
    
  public void setTimes(final double the_elapsed, final double the_single)
  {
      my_total_elapsed = String.valueOf(the_elapsed);
      my_single_elapsed = String.valueOf(the_single);
      my_total_sec = String.valueOf(the_elapsed/1000);
      my_single_sec = String.valueOf(the_single/1000);
      update();
  }
  
  private void update()
  {
      repaint();
  }
  
  /**
   * Paints the times to the panel.
   * @param the_graphics are the 2D graphics.
   */
  @Override
  public void paintComponent(final Graphics the_graphics)
  {
    super.paintComponent(the_graphics);
    final Graphics2D g2d = (Graphics2D) the_graphics;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 16));
    
    g2d.setColor(TIME_ELAPSED_COLOR);
    g2d.drawString(my_total_elapsed, 160 + my_total_elapsed.length(), 30);
    g2d.drawString(my_total_sec, 160 + my_total_elapsed.length(), 60);
    
    g2d.setColor(TIME_SINGLE_COLOR);
    g2d.drawString(my_single_elapsed, 160 + my_single_elapsed.length(), 90);
    g2d.drawString(my_single_sec, 160 + my_single_elapsed.length(), 120);
    
    g2d.setColor(TIME_SUFFIX_COLOR);
    g2d.drawString("Elapsed: ", 15, 30);
    g2d.drawString("Single:    ", 15, 90);
    
    g2d.drawString("Elapsed (Sec.):    ", 15, 60);
    g2d.drawString("Single (Sec.):    ", 15, 120);
  }
    
}
